﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace blackhouse.Web {
	public class DefaultPageProvider : PageProvider {

		#region Fields

		private Page _page;

		#endregion

		#region Properties

		private Page page {
			get {
				if(_page == null) {
					if(HttpContext.Current != null && HttpContext.Current.Handler != null)
						this._page = HttpContext.Current.Handler as Page;
				}
				return this._page;
			}
		}

		#endregion

		public override void SetCanonicalUrl(string url) {
			if(this.page != null && this.page.Header != null) {
				this.page.Header.Controls.Add(new LiteralControl("<link rel='canonical' href='" + url + "/' />"));
			}
		}

		public override void SetPageDescription(string description) {
			if(this.page != null && this.page.Header != null) {
				this.page.Header.Controls.Add(new LiteralControl("<meta name=\"Description\" content=\"" + description + "\" />"));
			}
		}

		public override void SetPageKeywords(string keywords) {
			if(this.page != null && this.page.Header != null) {
				this.page.Header.Controls.Add(new LiteralControl("<meta name=\"Keywords\" content=\"" + keywords + "\" />"));
			}
		}

		public override void SetPageTitle(string title) {
			if(this.page != null)
				this.page.Title = title;
		}

	}
}